package com.balance.anole.erp.security.login.action;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.PlatformUI;

import com.balance.anole.erp.security.SessionManager;
import com.balance.anole.erp.util.Messages;

public class LogoutAction extends Action {

	public static final String ID = "com.balance.anole.erp.security.login.action.LogoutAction"; //$NON-NLS-1$

	public LogoutAction(){
		setImageDescriptor(com.balance.anole.erp.Activator.getImageDescriptor("/icons/Logout.png")); //$NON-NLS-1$
		setText(Messages.LogoutAction_Logout);
		setId(ID);
	}

	@Override
	public void run() {
		boolean confirmed = MessageDialog.openConfirm(Display.getCurrent().getActiveShell(), Messages.LogoutAction_confirm, Messages.LogoutAction_logout_confirm);
		if(!confirmed){
			return;
		}
		super.run();
		SessionManager.getInstance().logout();
		PlatformUI.getWorkbench().restart();
	}
}
